/*
* 资产盘点计划中的盘点表
* */
import React, {Component} from 'react';
import {observer, inject} from 'mobx-react';
import {withRouter} from 'react-router-dom';
import {Form} from "weaver-mobile-page";
import {ActivityIndicator, Button, Tools} from "weaver-mobile";
import {getRouteParams} from '../../util'

const getLabel = Tools.getLabel;

@inject('inventoryFormStore')
@withRouter
@observer
export default class InventoryForm extends Component {
    componentWillMount() {
        this.Init(this.props)
    }

    componentWillReceiveProps(nextProps, nextContext) {
        this.Init(nextProps)
    }

    Init = (props) => {
        const {inventoryFormStore} = props;
        const {id, cptid, viewAttr} = getRouteParams(props);
        inventoryFormStore.init(id, cptid, viewAttr);
    };

    render() {
        const {inventoryFormStore, history} = this.props;
        const {inventoryForm, isLoading,viewAttr} = inventoryFormStore;
        const {cancelSubmit, submitInfo} = inventoryFormStore;
        return (<div className='inventory-form-box' style={{marginBottom:(viewAttr === '1' ? 0:(window.getThemeVars ? window.getThemeVars()["button-height"] : 47))}}>
            {isLoading ?
                (<div className='loading'><ActivityIndicator animating size='large'/></div>)
                :
                <Form store={inventoryForm}/>
            }
            {viewAttr !== '1' ? <div className="cpt-button-group">
                <Button type="ghost" className='cpt-button-cancel' onClick={() => {
                    cancelSubmit(history)
                }}>{getLabel(31129, "取消")}</Button>
                <Button type="primary" className='cpt-button-apply' onClick={() => {
                    submitInfo(history);
                }}>{getLabel(826, "确定")}</Button>
            </div> : null}
        </div>)
    }
}
